/**
 * @file   DataBusServer.cpp
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2013-05-03
 * @brief  DataBus Server.
 *
 * Copyright (C) 2013  Djuro Drljaca <djurodrljaca@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "DataBusServer.h"

DataBusServer::DataBusServer(QObject *parent)
    : DataBus::Server(parent),
    m_clientListModel(this)
{
}

DataBusServer::~DataBusServer()
{
}

DataBusClientListModel * DataBusServer::getClientListModel()
{
    return &m_clientListModel;
}

void DataBusServer::removeAllClients()
{
    m_clientListModel.removeAllClients();

    Server::removeAllClients();
}

bool DataBusServer::removeClient(const int index)
{
    const DataBus::Client *client = getClient(index);

    if (client == 0)
    {
        return false;
    }

    m_clientListModel.removeClient(client->getClientId());

    return Server::removeClient(index);
}

quint8 DataBusServer::registerClient(const DataBus::Client *client, const DataBus::Packet &packet)
{
    quint8 ret = DataBus::Server::registerClient(client, packet);

    if (ret == RETURN_STATUS_SUCCESS)
    {
        m_clientListModel.addClient(client->getClientId());
    }

    return ret;
}
